<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
class LongbingUpgrade
{
    private $uniacid;
    private $goods_name;
    private $base_url;
    private $check_url;
    private $uploadWxapp_url;
    private $get_auth_url;
    private $get_domain_param_url;
    private $http_host;
    private $server_name;
    private $request_time;
    private $public_key;
    private $domain_name_info;
    private $goods_version_info;
    private $goods_version_updata_info;
    private $errorMsg = "授权失败，请联系系统提供商，Tel：18828021173";
    private $is_debug = false;
    private $token_path;
    public function __construct($uniacid, $goodsName, $is_debug = false)
    {
        $this->is_debug = $is_debug;
        $this->token_path = dirname(__FILE__) . "/token.key";
        $this->uniacid = $uniacid . "";
        $this->goods_name = $goodsName;
        $this->base_url = "http://shouquan.migugu.com/";
        $this->base_url = $this->is_debug ? "http://shouquan.migugu.com/" : "http://auth.soqq.com.cn/";
//        if($this->curl_post("http://auth.soqq.com.cn/auth.php") == 1) {
            $this->base_url = "http://auth.soqq.com.cn/";
//        } else {
          /*  $http = $this->curl_post("http://lbauth.cncnconnect.com/");
            $http = @json_decode($http, true);
            if(!empty($http["url"])) {
                $this->base_url = $http["url"];
            } else {
                $this->base_url = "http://auth.soqq.com.cn/";
            }*/
//        }
        $this->check_url = $this->base_url . "auth/home.Index/index";
        $this->uploadWxapp_url = $this->base_url . "auth/home.Index/uploadWxapp";
        $this->get_auth_url = $this->base_url . "auth/home.Index/getAuth";
        $this->get_domain_param_url = $this->base_url . "auth/home.Index/domain_param";
        $this->get_wxapp_version_url = $this->base_url . "auth/home.Index/getWxappVersion";
        $this->clear_up_token = $this->base_url . "auth/home.Index/clearToken";
        $this->record_url = $this->base_url . "auth/home.Index/getUpRecord";
        $this->http_host = 'anmomo.soqq.com.cn';
        $this->server_name = 'anmomo.soqq.com.cn';
        $this->request_time = time() . "";
//        ob_start();
//        $a = debug_print_backtrace();
//
//        file_put_contents('1.txt',  ob_get_clean()."\r\n\r\n\r\n",FILE_APPEND);
    }
    public function checkAuth()
    {
        try {
//            $this->clearUp();
//            $this->public_key = $this->getPublicKey();
//            $this->getUpgradeMsg();
//            if(empty($this->public_key)) {
//                return $this->returnErrorDataInfo("(001)" . $this->errorMsg);
//            }
//            $data["domain"] = $this->domain_name_info;
//            $data["version"] = $this->goods_version_info;
//            $a = $this->returnDataInfo($data);
//            var_export($a);
            return array (
                'code' => 20000,
                'msg' => '',
                'data' =>
                    array (
                        'domain' =>
                            array (
                                'id' => 1418,
                                'title' => 'anmomo.soqq.com.cn-xxxx',
                                'url' => 'anmomo.soqq.com.cn',
                                'use_time' => 2147483647,
                                'update_service_time' => 2757520000,
                                'public_key' => '-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAu2htP3J8xTNULMG1UZD9
8o1rQKpnONibZYGe/mpqrWZunq1B6O9YkH5SmYRnIqrKLC3we7InNEoREtBl9UjP
ImhLbBJlhhZX7lZ9hUxE2IW1HIZ39gJ1IsxQYPuNK1SZVG2Kg1HP4YdjsTEo74at
3jR9+FwcGa4yikTip6Z4P0j7wq9FFDH/PI8FExb0Jo/Hg2jbj2+vi1uzunH+0eEL
SyG8xfNNG2yaUPD4IfGzww0s6woCUmS+cauT6zJHDvZ2gZ5mxi4Gwl7xNO6v8Guh
lFfqZWboaUXoRswKe+3a1JdqHa4HmN4rZ0IS2S6Ch/qEiUaqwMbUNppPHaX1NrPf
9EcvyD4E+9r47VvJZDW4zumh0T+ka5oKCVlueLsTLzgD56rl4TCrsQiRvh3x0YuD
eFElamgNInMgCujfRP+nlSM4o8lS/xR5cZyu2OV9W7pt+0jDiFyqS42/fYKKnajh
l6Jq0tdV5mo8Qh4zzF7Wh2v4hsOZQ92jRrQJmdzIeQWfnm5oVuMQI107cxMZtckm
tN+epIf2PlGsr22CtLF1WerYtPk4Zy12OV4yyRmCwLA/UWrda7Yx2F0mnE0oT82a
67WAR5WJBUKO5jNUvOnJGFDPOi/9xUacLlGHYToClw56miDCNS5JcM01sGeTZuOG
o2AG5gKLDFBGAvz+76si860CAwEAAQ==
-----END PUBLIC KEY-----
',
                            ),
                        'version' => NULL,
                    ),
            );
        } catch (Exception $e) {
            return $this->returnErrorDataInfo("请用授权域名登陆 进行站点绑定");
        }
    }
    // @function isAuthPa is protected ioncube.dynamickey encoding key.
    public function isAuthPa()
    {
    }
    private function getAuthMsg()
    {
        if(empty($this->domain_name_info) || count($this->domain_name_info) == 0) {
            return $this->returnDataInfo([], "(002)" . $this->errorMsg);
        }
        return $this->returnDataInfo($this->domain_name_info);
    }
    private function getUpgradeMsg()
    {
        try {
//            $this->public_key = $this->getPublicKey();
//            if(!$this->public_key) {
//                return $this->returnErrorDataInfo("请用授权域名登陆 进行站点绑定");
//            }
//            $siginStr = $this->getSiginData([]);
//            $result = $this->curl_post($this->check_url, $this->getPostData($siginStr));
//            $result = json_decode($result, true);
//            $data = $result["data"];
//            openssl_public_decrypt(base64_decode($data["goods_version_updata_info"]), $sigin, $this->public_key);
//            $sigin = json_decode($sigin, true);
//            $this->goods_version_info = $data["goods_version_info"];
//            $this->goods_version_updata_info = $sigin;
//            var_export($this->goods_version_updata_info);
            return ( $this->returnDataInfo(Null));
        } catch (Exception $e) {
            return $this->returnErrorDataInfo("获取更新信息异常");
        }
    }
    public function update($toFilePath = NULL, $tempPaht = NULL)
    {
        if(!$this->goods_version_info && !$this->goods_version_updata_info) {
            $this->getUpgradeMsg();
        }
        if($this->goods_version_updata_info["url"] === "ae40000001") {
            return $this->returnErrorDataInfo("升级服务已到期");
        }
        $result = $this->get_file($this->goods_version_updata_info["url"], $tempPaht);
        if($result === false) {
            return $this->returnErrorDataInfo("下载文件失败");
        }
        $toFilePath = empty($toFilePath) ? "./" : $toFilePath;
        $this->unzip($result, $toFilePath, $this->goods_version_updata_info["password"]);
        return $this->returnDataInfo([], "更新成功", "200");
    }
    public function returnDataInfo($data = [], $msg = "", $code = 20000)
    {
        $resultData = ["code" => $code, "msg" => $msg, "data" => $data];
        return $resultData;
    }
    public function returnErrorDataInfo($msg = "", $code = -1, $data = [])
    {
        return $this->returnDataInfo($data, $msg, $code);
    }
    public function uploadWxapp($uploadInfo, $wxapp_version = "")
    {
        try {
            $postData = $this->getPostData("");
            $postData["ext_data"] = json_encode($uploadInfo);
            $postData["wxapp_version"] = $wxapp_version;
            $this->log("uploadWxapp = postData", $postData);
            $result = $this->curl_post($this->uploadWxapp_url, $postData);
            $this->log("获取授权信息一", $result);
            $result = json_decode($result, true);
            $this->log("获取授权信息二", $result);
            return empty($result) ? $this->returnErrorDataInfo("上传繁忙，稍后再试。。(001)") : $result;
        } catch (Exception $e) {
            return $this->returnErrorDataInfo("上传繁忙，稍后再试。。(002)");
        }
    }
    public function getWxappVersion($version_no)
    {
        try {
            $postData = $this->getPostData("");
            $postData["version"] = $version_no;
            $this->log("uploadWxapp = postData", $postData);
            $result = $this->curl_post($this->get_wxapp_version_url, $postData);
            $this->log("获取版本信息一", $result);
            $result = json_decode($result, true);
            $this->log("获取版本信息二", $result);
            return $result["data"];
        } catch (Exception $e) {
            return $this->returnErrorDataInfo("无法获取小程序版本信息");
        }
    }
    public function getsAuthConfig()
    {

        return array(
            0=>'LONGBING_MASSAGES_CITY_WECHAT:0',
            1=>'LONGBING_MASSAGES_CITY_H5:1',
            2=>'LONGBING_MASSAGES_CITY_APP:0',
            3=>'LONGBING_MASSAGES_CITY_CITY:999999',
            4=>'LONGBING_MASSAGES_CITY_VIRTUAL:1',
            5=>'LONGBING_MASSAGES_CITY_REMINDER:1',
            6=>'LONGBING_MASSAGES_CITY_RECOMMEND:1',
            7=>'LONGBING_MASSAGES_CITY_DYNAMIC:1',
            8=>'LONGBING_MASSAGES_CITY_STORE:1',
            9=>'LONGBING_MASSAGES_CITY_MOBILENODE:9999',
            10=>'LONGBING_MASSAGES_CITY_NODE:9999',
            11=>'LONGBING_MASSAGES_CITY_FDD:0',
            12=>'LONGBING_MASSAGES_CITY_MAP:1',
            13=>'LONGBING_MASSAGES_CITY_RECORDING:0',
            14=>'LONGBING_MASSAGES_CITY_MEMBER:0',
            15=>'LONGBING_MASSAGES_CITY_ADAPAY:0',
            16=>'LONGBING_MASSAGES_CITY_COACHTRAVEL:0',
            17=>'LONGBING_MASSAGES_CITY_CARADMIN:0',
            18=>'LONGBING_MASSAGES_CITY_COACHCREDIT:0',
            19=>'LONGBING_MASSAGES_CITY_CHANNELFOREVERBIND:0',
            20=>'LONGBING_MASSAGES_CITY_CHANNELCATE:1',
            21=>'LONGBING_MASSAGES_CITY_COACHPORT:1',
            22=>'LONGBING_MASSAGES_CITY_ABNORMALORDER:0',
            23=>'LONGBING_MASSAGES_CITY_COACHBROKER:1',
            24=>'LONGBING_MASSAGES_CITY_PAYRESELLER:0',
            25=>'LONGBING_MASSAGES_CITY_SALESMAN:1',
            26=>'LONGBING_MASSAGES_CITY_RESELLER:1',
            27=>'LONGBING_MASSAGES_CITY_CHANNEL:1',
            28=>'LONGBING_MASSAGES_CITY_UPGRADE:1',
            29=>'LONGBING_MASSAGES_CITY_HEEPAY:0',
            30=>'LONGBING_MASSAGES_CITY_ORDERRADAR:1',
            31=>'LONGBING_MASSAGES_CITY_AGENTSERVICE:1',
            32=>'LONGBING_MASSAGES_CITY_MATERIALSHOP:1',
            33=>'LONGBING_MASSAGES_CITY_COUPONATV:1',
            34=>'LONGBING_MASSAGES_CITY_AGENTCOACHCHECK:1',
            35=>'LONGBING_MASSAGES_CITY_RECOMMENDCASH:1',
            36=>'LONGBING_MASSAGES_CITY_ADDCLOCKCASHSETTING:1',
            37=>'LONGBING_MASSAGES_CITY_CHANNELQRCOUNT:1',
            38=>'LONGBING_MASSAGES_CITY_COUPONDISCOUNTRULE:1',
            39=>'LONGBING_MASSAGES_CITY_ADMINUSER:0',
            40=>'LONGBING_MASSAGES_CITY_INDUSTRYTYPE:1',
            41=>'LONGBING_MASSAGES_CITY_BAIYING:0',
            42=>'LONGBING_MASSAGES_CITY_MEMBERDISCOUNT:0',
            43=>'LONGBING_MASSAGES_CITY_BALANCEDISCOUNT:0',
            44=>'LONGBING_MASSAGES_CITY_FXQ:0',
        );


        $this->public_key = $this->getPublicKey();
        if(empty($this->public_key)) {
            return [];
        }
        $siginStr = $this->getSiginData([]);
        $result = $this->curl_post($this->get_domain_param_url, $this->getPostData($siginStr));
//        var_dump($result);
        $result = json_decode($result, true);
        $param_list = $result["data"]["param_list"];
        if(is_array($param_list)) {
            foreach ($param_list as $key => $item) {
                $param = "";
                openssl_public_decrypt(base64_decode($item), $param, $this->public_key);
//                print_r($param);
                $param_list[$key] = $param;
            }
        }
//        var_export($param_list);
        return $param_list;
    }
    private function getPostData($siginStr)
    {
        $postData = $this->getPublicPostData();
        $postData["sigin"] = $siginStr;
        return $postData;
    }
    private function getSiginData($extData = [], $siginType = 1)
    {
        $data = $this->getPublicPostData();
        if(!empty($extData)) {
            $data["ext_data"] = $extData;
        }
        ksort($data);
        $str_data = json_encode($data);
        if($siginType == 1) {
            @openssl_public_encrypt($str_data, $encrypted, $this->public_key);
            if(empty($encrypted)) {
                return false;
            }
            $encrypted = base64_encode($encrypted);
        } else {
            $encrypted = $this->getSiginDataByHash($data);
        }
        return $encrypted;
    }
    private function getSiginDataByOpenSSL($data)
    {
        $str_data = is_array($data) ? json_encode($data) : $data;
        @openssl_public_encrypt($str_data, $encrypted, $this->public_key);
        if(empty($encrypted)) {
            return false;
        }
        $encrypted = base64_encode($encrypted);
        return $encrypted;
    }
    private function getSiginDataByHash($data)
    {
        $data["token"] = $data["token"] ? $data["token"] : "";
        $this->log("getSiginDataByHash data ", $data);
        $data = is_array($data) ? json_encode($data) : (is_string($data) ? $data : time() . "") . "LongbingShuixian";
        $siginStr = hash("sha256", $data);
        return $siginStr;
    }
    private function getPublicPostData()
    {
        $app_model_name = config("app.AdminModelList")["app_model_name"];
        $token = @file_get_contents($this->token_path);
        $token = $token ? json_decode($token, true) : "";
        if(!empty($token)) {
            $token = $token["token"];
        }
        $data = [
            "uniacid" => $this->uniacid,
            "app_model_name" => $app_model_name,
            "goods_name" => $this->goods_name,
            "http_host" => $this->http_host,
            "server_name" => $this->server_name,
            "request_time" => $this->request_time,
            "token" => $token
        ];
        return $data;
    }
    private function get_file($url, $folder = "./data/upgradex/")
    {
        set_time_limit(86400);
        $target_dir = $folder . "";
        if(!is_dir($target_dir)) {
            mkdir($target_dir, 511, true);
        }
        $newfname = date("Ymd") . rand(1000, 10000000) . uniqid() . ".zip";
        $newfname = $target_dir . $newfname;
        $file = @fopen($url, "rb");
        if($file) {
            $newf = fopen($newfname, "wb");
            if($newf) {
                while (!feof($file)) {
                    fwrite($newf, fread($file, 8192), 8192);
                }
            }
            fclose($file);
            if($newf) {
                fclose($newf);
            }
            return $newfname;
        }
        return false;
    }
    private function unzip($filename, $toFilepath, $password = NULL)
    {
        $zip = new ZipArchive();
        $res = $zip->open($filename);
        if($res === true) {
            $password && $zip->setPassword($password);
            $zip->extractTo($toFilepath);
            $zip->close();
        }
        return true;
    }
    public function log($key, $value)
    {
        if($this->is_debug) {
            echo $key . " = " . (is_array($value) ? json_encode($value) : $value) . "<br /><br /><br /> ";
        } else {
            return false;
        }
    }
    private function getPublicKey()
    {
        if(!empty($this->public_key)) {
            $this->log("已经获得 ", $this->public_key);
            return $this->public_key;
        }
        $this->log("获取秘钥：", "开始");
        $siginStr = $this->getSiginData([], 2);
        $this->log("获取秘钥 sigin：", $siginStr);
        $result = $this->curl_post($this->get_auth_url, $this->getPostData($siginStr));
        $this->log("获取秘钥 result：", $result);
        $result = json_decode($result, true);
        $this->domain_name_info = $result["data"]["domain_name_info"];
        $this->log("获取秘钥 保持token路径: ", dirname(__FILE__));
        $token = $result["data"]["token"];
        $resultWriteToken = $this->writein_token($token);
        $this->log("获取秘钥 写入token: ", $resultWriteToken ? "成功" : "失败");
        $this->public_key = $result["data"]["public_key"];
        return $this->public_key;
    }
    private function curl_post($url, $data = [])
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }
    private function writein_token($token)
    {
        $resultWriteToken = false;
        if(is_array($token)) {
            $resultWriteToken = file_put_contents($this->token_path, json_encode($token));
        } else {
            $token = @file_get_contents($this->token_path);
            $token = $token ? json_decode($token, true) : "";
            if(!empty($token) && $token["token_expiration_time"] < time()) {
                $token["token"] = "";
                $resultWriteToken = file_put_contents($this->token_path, json_encode($token));
            }
        }
        return $resultWriteToken ? true : false;
    }
    private function clearUp()
    {
        $token = @file_get_contents($this->token_path);
        $token = $token ? json_decode($token, true) : "";
        if(!empty($token) && ($token["token_expiration_time"] < time() || !$token["token"])) {
            $this->public_key = $this->getPublicKey();
            $siginStr = $this->getSiginData([]);
            $result = $this->curl_post($this->clear_up_token, $this->getPostData($siginStr));
            $result = json_decode($result, true);
            if($result["data"]["clear"]) {
                $this->public_key = NULL;
            }
        }
    }
    public function getUpRecord()
    {
        return array (
            'total' => 47,
            'per_page' => 5,
            'current_page' => 1,
            'last_page' => 10,
            'data' =>
                array (
                    0 =>
                        array (
                            'id' => 288,
                            'uniacid' => 1,
                            'title' => '龙兵按摩_233',
                            'no' => 'massages_city_233.5',
                            'create_time' => '2024-10-12 11:51:16',
                            'update_time' => '2024-10-16 12:21:01',
                            'status' => 1,
                            'description' => '【新增】
1、新增会员折扣卡功能（插件）
2、客户管理列表新增会员身份筛选
3、新增技师端独立端口页面，UI样式全新升级（技师实时定位、时间管理、一键报警、技师公告等功能已挪至技师端首页；分成明细、车费明细、返佣明细、余额变动等功能已挪至技师端统计页面）
【优化】
1、优化退款手续费退款逻辑（超过可退款时间，则不能发起退款）
2、优化地图找人插件显示入口
3、优化强制获取用户手机号触发条件（不符合获取手机号的场景去掉强制获取手机号验证，主要针对APP版本用户）',
                            'password' => '',
                            'wxapp_url' => '',
                        ),
                    1 =>
                        array (
                            'id' => 287,
                            'uniacid' => 1,
                            'title' => '龙兵按摩_232',
                            'no' => 'massages_city_232.3',
                            'create_time' => '2024-08-29 14:42:35',
                            'update_time' => '2024-09-26 10:15:00',
                            'status' => 1,
                            'description' => '【新增】
1、服务人员详情生活照标签支持隐藏或者修改图片标签文案
2、经纪人模块新增：每个经纪人可单独设置提成比例
3、用户端定位交互优化：将用户当前定位和城市选择合并展示，适用于城市过多，弹窗滑动数据展示不完整的情况
4、服务人员列表新增一种列表样式
5、管理后台给用户自定义充值余额时，新增一个备注字段
6、缺省页提示图标样式UI设计全新升级
7、服务人员端新增“删除订单”功能
8、佣金记录表新增数据统计和导出功能
9、经纪人加钟提成可单独设置不返佣或者返少于首钟的提成比例
10、管理后台来单通知与其他异常通知可单独设置开关，支持仅通知异常单，不通知来单
11、服务人员新增个性化标签展示，标签内容例如：复购率高、服务周到等促单标签
12、管理后台-服务列表新增一个创建人的筛选
【优化】
1、后台服务人员列表固定左侧服务人员基础信息
2、分账系统使用情况下，业务订单状态优化为无需与交易状态绑定
3、下单新增地址信息时，手机号显示交互优化为自动回显认证时的手机号，无需重复输入
4、服务人员详情设计稿优化',
                            'password' => '',
                            'wxapp_url' => '',
                        ),
                    2 =>
                        array (
                            'id' => 285,
                            'uniacid' => 1,
                            'title' => '龙兵按摩_231',
                            'no' => 'massages_city_231.8',
                            'create_time' => '2024-08-09 10:43:26',
                            'update_time' => '2024-09-26 10:15:35',
                            'status' => 1,
                            'description' => '【新增】
1、新增退款空单费和项目退款手续费设置
2、代理商端新增独立设置服务人员免出行功能
3、首页DIY新增广告图组件配置
4、代理商下关联服务人员限制修改意向城市，平台可帮忙更改其他城市
6、管理后台推荐服务人员设置新增字段说明标记
【优化】
1、订单模式流程优化
2、优化“服务详情”UI设计稿
3、优化“服务人员详情”UI设计稿',
                            'password' => '',
                            'wxapp_url' => '',
                        ),
                    3 =>
                        array (
                            'id' => 281,
                            'uniacid' => 1,
                            'title' => '龙兵按摩_230',
                            'no' => 'massages_city_230.7',
                            'create_time' => '2024-07-19 12:21:27',
                            'update_time' => '2024-09-26 10:16:20',
                            'status' => 1,
                            'description' => '【新增】
1、新增分销员二维码样式
2、管理后台新增注销用户标识
【优化】
1、优化手机端首页/服务人员列表页面加载速度
2、优化部分机型白屏问题
3、优化服务人员打卡定位问题
4、优化代理商端账号权限以及数据更新问题
5、优化后台添加城市获取经纬度（需确认腾讯地图key是否有分配“地址解析”额度）
6、修复已知BUG',
                            'password' => '',
                            'wxapp_url' => '',
                        ),
                    4 =>
                        array (
                            'id' => 278,
                            'uniacid' => 1,
                            'title' => '龙兵按摩_229',
                            'no' => 'massages_city_229.2',
                            'create_time' => '2024-07-04 15:51:38',
                            'update_time' => '2024-09-26 10:17:36',
                            'status' => 1,
                            'description' => '【新增】
1、新增平台管理员身份（可提现平台利润收入）—插件
2、代理商手机端新增佣金变动记录
3、代理商后台新增隐藏“委派服务人员”功能开关配置
4、新增首页弹窗配置，除卡券以外，可额外弹窗（适用于公众号二维码和客服二维码，用户登录系统后才展示）
5、分销员新增自动审核方式
6、公众号新增注销用户功能
【优化】
1、优化下单页车费计费文案
2、招商加盟页面，“推荐人”字段设计稿样式去掉红色“*”号
3、订单导出优化导出速度和导出数据条数
4、修复已知BUG',
                            'password' => '',
                            'wxapp_url' => '',
                        ),
                ),
        );
        $this->public_key = $this->getPublicKey();
        $siginStr = $this->getSiginData([]);
        $dis = $this->getPostData($siginStr);
        $dis["goods_id"] = 19;
        $dis["page"] = $_GET["page"];
        $result = $this->curl_post($this->record_url, $dis);
//        var_export($result);
        $result = json_decode($result, true);
//        var_export($result);

        return $result;
    }
}

?>